package com.hxd.mall.module.startup

import android.view.View
import android.view.ViewGroup
import androidx.viewpager.widget.PagerAdapter
import androidx.viewpager.widget.ViewPager

class WelcomeAdapter(private val viewList: List<View>?) : PagerAdapter() {
    override fun getCount(): Int {
        return if (viewList != null && viewList.isNotEmpty()) viewList.size else 0
    }

    override fun isViewFromObject(view: View, `object`: Any): Boolean {
        return view === `object`
    }

    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        container.addView(viewList!![position].apply { layoutParams = ViewPager.LayoutParams() })
        return viewList[position]
    }

    override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
        container.removeView(viewList!![position])
    }
}